//
//  AZBaseTableViewController.swift
//  sinaWB
//
//  Created by AzeryKiss on 16/2/25.
//  Copyright © 2016年 AzeryKiss. All rights reserved.
//

import UIKit

var lalaislogin:Bool = false

class AZBaseTableViewController: UITableViewController,sinaVisitorDelegate, AZOauthDelegate {
    
    var visitor: AZLoginView?
    
//    override func viewWillAppear(animated: Bool) {
//        super.viewWillAppear(animated)
//
//    }

    override func loadView() {
        super.loadView()

            AZUserViewModel().isLogin ? superrLoadView() : loadLoginView()

        
//        if lalaislogin{
//            super.loadView()
//
//        } else {
//          
//            visitor = AZLoginView()
//            
//            view = visitor
//            
//            
//            visitor?.delegate = self
//        }
        
    }
    
    func superrLoadView(){
        super.loadView()

//        return
    }
    
    // 如果没有登录的话 加载登陆的界面
    func loadLoginView(){
        visitor = AZLoginView()
        
        view = visitor
        
        
        visitor?.delegate = self
        
        addNavBtn()

    }
    

    override func viewDidLoad() {
        super.viewDidLoad()


    }
    
//    override func viewWillAppear(animated: Bool) {
//        
//        super.viewWillAppear(animated)
//        
//        if !islogin{
//            
//            visitor = AZLoginView()
//            
//            view = visitor
//            
//            
//            visitor?.delegate = self
//            
//        } 
//        
//    }
    
    // 添加导航栏的按钮
    func addNavBtn() {
        

        
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegisterMethod")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didLoginMethod")
    }


    //注册方法
    func didRegisterMethod() {

    }
    
    // 登录方法
    func didLoginMethod() {

            let ouath = AZOauthViewController()
            
            ouath.delegate = self
            
            let nav = UINavigationController(rootViewController: ouath)
            
            presentViewController(nav, animated: true) { () -> Void in
                

        }
    }
    
    func loginSuccessMethod() {
//        islogin = true
//         AZUserViewModel.shareInstance.isLogin = true
//        loadView()
//
//        dismissViewControllerAnimated(false, completion: nil)
//        for  childVc in self.tabBarController!.childViewControllers{
//            childVc.loadView()
//        }
        
    }

}






